<?php 
include_once '../../persistence/conection/connection.php';
include_once '../../model/usuario.php';
include_once '../../business/usuarioBS.php'; 
?>

<?php 
session_start();

$msgErro = null;
$login = null;
$senha = null;
if(isset($_POST["login"]) && isset($_POST["senha"])){	
	
	$login = $_POST["login"]; 
	$senha = $_POST["senha"];
	
	$connect = openConnection();
	$usuario = loginSistema($login, $senha, $connect);
	closeConnetion($connect);
	
	if($usuario != null){
		$_SESSION["usuarioLogado"] = serialize($usuario); 
		header('Location: ../../site/private/index.php');
		exit;
	}

}else{
	if(isset($_POST["login"])){
		$login = $_POST["login"];	
	}
	if(isset($_POST["senha"])){
		$senha = $_POST["senha"];	
	}
}

if(isset($_POST["msgErro"])){
	$msgErro = $_POST["msgErro"];
}
?>

<!DOCTYPE html>
<html>
	<meta http-equiv="Content-Type" content="text/html; iso-8859-1" />
	<meta http-equiv="Content-Language" content="PT-BR" />
	<meta name="language" content="portuguese" />
	<meta name="author" content="Milton Domingues" />
	<meta name="description" content="Sistema para colegios" />
	<meta name="keywords" content="Colegio avance matriculas colegial" />
	<meta name="URL" content="http://www.pointsistemas.com.br/" />
	<meta name="robots" content="index, follow" />
	<meta name="revisit-after" content="30 days" />
	<meta name="Target" content="_self" />
	<meta name="Page-Topic" content="" />
	<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<head> 
	<title>Portal do Estudante</title>
	<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css" />
	<link href="../../resources/css/style.css" rel="stylesheet" type="text/css" />
	
	<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
	<script src="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"></script>
	<script type="text/javascript" src="../../resources/js/core.js"></script>
</head>

<body>

	<div data-role="page"> 
		<div data-role="header" data-theme="b"><h1>Login</h1></div> 
		<div data-role="content" data-theme="b">
			<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
	
				<input type="hidden" name="msgErro" value="true">			
				
				<?php if($login == null && $msgErro != null){ ?>
					<span style="color: red;">O Campo Login e obrigatorio!</span><br/>
				<?php }?>
				<?php if($senha == null && $msgErro != null){ ?>
					<span style="color: red;">O Campo Senha e obrigatorio!</span>
				<?php }?>
								
				<label for="login">Login:</label>
				<input type="text" name="login" id="login">
				
				<label for="senha">Senha:</label>
				<input type="password" name="senha" id="senha" autocomplete="off">
				
				<input type="submit" value="logar"/>
			
			</form>
		</div> 
		<div data-role="footer" data-theme="b"><h1>Rodape</h1></div> 
	</div>

</body>

</html>